// packageFT/guide/grabbing-order/grabbing-order.js
const app = getApp()
Page({
  options: {
    styleIsolation: 'shared',
  },
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page:1,
    total:null
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getGoodsList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getGoodsList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getGoodsList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log('我触底了')
    if(this.data.list.length != this.data.total){
      this.setData({
        page: this.data.page+=1
      })
      this.getGoodsList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  linkCreate(){
    wx.navigateTo({
      url: '/packageDR/guide/createGoods/createGoods',
    })
  },
  linkDetail(e){
    console.log(e)
    const id = e.currentTarget.dataset.goodsid
    wx.navigateTo({
      url: '/packageDR/guide/createGoods/createGoods?type=lookup&goodsid='+id,
    })
  },
  getGoodsList(){
    const _this = this
    let urlStr = app.getNetAddresss("plugin.talent.frontend.goods.get-goods-list");
    app._postNetWork({
      url: urlStr,
      data:{page:_this.data.page},
      success: function(res) {
        const resData = res.data
        console.log(resData,'-------------')
        if (resData.result == 1) {
          _this.setData({
            list:resData.data.list.data,
            total:resData.data.list.total
          })
          _this.setData({
            list:_this.data.list
          })
        } else {
          app.tips(resData.msg)
        }
        wx.stopPullDownRefresh()
      },
      complete: function() {
        wx.hideLoading()
      }
    })
  }
})